{% extends "main.html" %}

{% load common %}

{% block title %}Host {{ host }} {% endblock %}

{% block content_title %}Host Information{% endblock %}

{% block breadcrumbs %}{{ block.super }} &rsaquo; <a href="{% url 'host_list' %}">Hosts</a> &rsaquo; {{ host }} {% endblock %}

{% block content %}

<div class="module">
    <h2>{{host}}</h2>
    <table>
        <tr><td>Hostname</td><td> {{ host.hostname }} </td></tr>
        <tr><td>Domain</td><td> <a href="{% url 'host_list' %}?domain={{ host.domain.id }}">{{ host.domain }}</a> </td></tr>
        <tr><td>Reporting IP Address</td><td> {{ host.ipaddress }} </td></tr>
        <tr><td>Reverse DNS</td><td> {{ host.reversedns }} </td></tr>
        <tr><td>OS</td><td> <a href="{{ host.os.get_absolute_url }}">{{ host.os }}</a> </td></tr>
        <tr><td>OS Group</td><td> <a href="{{ host.os.osgroup.get_absolute_url }}">{{ host.os.osgroup }}</a> </td></tr>
        <tr><td>Kernel</td><td> {{ host.kernel }} </td></tr>
        <tr><td>Architecture</td><td> {{ host.arch }} </td></tr>
        <tr><td>Tags</td><td>
            {% load tagging_tags %}
            {% tags_for_object host as tags %}
            {% for tag in tags %}
                <a href="{% url 'host_list' %}?tag={{ tag }}">{{ tag }}</a>
            {% endfor %}
        </td></tr>
        <tr><td>Last Update</td><td> {{ host.lastreport }} </td></tr>
        <tr><td>Updates Available</td><td> <a href="#updates">{{ host.updates.count }}</a> </td></tr>
        <tr><td>Reboot Required</td><td> {{ host.reboot_required }} </td></tr>
        <tr><td>Packages Installed</td><td> <a href="#installedpackages">{{ host.packages.count}}</a> </td></tr>
        <tr><td>Repos In Use</td><td>{% if host.host_repos_only %}Host Repos{% else %}Host and OS Group Repos{% endif %}</td></tr>
        <tr><td>Last 3 reports</td><td>
            {% for report in reports %}
            <span class="brick" style="{% cycle 'background:#bfdddd' 'background:#deeeee' %}">
                <a class="dark" href="{{ report.get_absolute_url}}">{{ report.created }} </a>
            </span>
            {% endfor %}
        </td></tr>
    </table>
</div>
{% if user.is_authenticated %}
    {% if perms.is_admin %}
    <div class="module">
        <h2>Actions</h2>
        <a class="brick" href="{% url 'host_delete' host.hostname %}">Delete this host</a>
        <a class="brick" href="{% url 'host_edit' host.hostname %}">Edit this host</a>
        <div class="clearbrick"></div>
    </div>
    {% endif %}
{% endif %}
<div class="module" id="updates">
    <h2>Updates Available</h2>
    <table>
        <thead>
            <tr><th></th><th>Installed</th><th>Available</th></tr>
        </thead>
        {% for update in host.updates.select_related %}
        <tr>
            <td>
            {% if update.security %}
            <span class="secupdate">
            {% else %}
            <span class="update">
            {% endif %}
            &nbsp;&nbsp;&nbsp;</span>
            </td>
            <td>
                <a href="{{ update.oldpackage.name.get_absolute_url }}"> {{ update.oldpackage }} </a>
            </td>
            <td>
                <a href="{{ update.newpackage.name.get_absolute_url }}"> {{ update.newpackage }} </a>
            </td>
        </tr>
        {% endfor %}
    </table>
</div>
<div class="module">
  <h2>Repositories</h2>
    <table>
      <thead>
        <tr>
          <th>Name</th><th>Type</th><th>Priority</th><th>Enabled</th><th>Security</th>
        </tr>
      </thead>
      <tbody>
    {% if hostrepos %}
      {% for hostrepo in hostrepos %}
        <tr class="{% cycle 'row1' 'row2' %}">
          <td> <a href="{{ hostrepo.repo.get_absolute_url }}">{{ hostrepo.repo.name }}</a> </td>
          <td>Host</td>
          <td>{{ hostrepo.priority }}</td>
          <td class="centered"> {% yes_no_img hostrepo.enabled %} </td>
          <td class="centered"> {% yes_no_img hostrepo.repo.security %} </td>
        </tr>
      {% endfor %}
    {% endif %}
    {% with host.os.osgroup.repos.select_related as osrepos %}
    {% if osrepos and not host.host_repos_only %}
      {% for osrepo in osrepos %}
        {% if osrepo.arch == host.arch %}
          <tr class="{% cycle 'row1' 'row2' %}">
            <td> <a href="{{ osrepo.get_absolute_url }}">{{ osrepo.name }}</a> </td>
            <td>OS Group</td>
            <td>N/A</td>
            <td class="centered"> {% yes_no_img osrepo.enabled %} </td>
            <td class="centered"> {% yes_no_img osrepo.security %} </td>
          </tr>
        {% endif %}
      {% endfor %}
    {% endif %}
    {% endwith %}
      </tbody>
    </table>
</div>
<div class="module" id="installedpackages">
    <h2>Packages</h2>
    <div class="resultslink" id="r1"><a href="#">Show/Hide Installed Packages</a></div>
        <div class="results" id="r1">
            {% for package in host.packages.select_related %}
            <span class="brick" style="{% cycle 'background:#bfdddd' 'background:#deeeee' %}">
            <a class="dark" href="{{ package.name.get_absolute_url }}"> {{ package }} </a></span>
            {% endfor %}
        </div>
</div>
{% endblock %}

